package com.example.demo.controller;

import com.example.demo.pojo.Detection;
import com.example.demo.pojo.request.DetectionRequest;
import com.example.demo.service.DetectionService;
import com.example.demo.service.UserService;
import com.example.demo.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author 程序员小洋
 * @version 2022.3
 * @date 2023/5/9 09:20
 * @title 检测控制器
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/detection")
@CrossOrigin
@Api(tags = "检测控制器")
public class DetectionController {

    @Autowired
    private DetectionService detectionService;

    /**
     * 新增
     * @param detection
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增")
    public Result save(@RequestBody Detection detection) {
        detectionService.save(detection);
        return Result.success();
    }

    /**
     * 修改
     * @param detection
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改")
    public Result update(@RequestBody Detection detection) {
        detectionService.update(detection);
        return Result.success();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除")
    public Result delete(@PathVariable Integer id) {
        detectionService.deleteById(id);
        return Result.success();
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public Result getById(@PathVariable Integer id) {
        Detection detection = detectionService.getById(id);
        return Result.success(detection);
    }

    /**
     * 条件查询
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("条件查询")
    public Result list(DetectionRequest detectionRequest) {
        List<Detection> list = detectionService.list(detectionRequest);
        return Result.success(list);
    }

}
